// Usage: node backend/scripts/migrate-roles.js
const mongoose = require('mongoose');
const connectDB = require('../config/database');
const { User } = require('../models');

(async () => {
  try {
    await connectDB();
    const result = await User.updateMany({ role: 'editor' }, { $set: { role: 'project_admin' } });
    console.log(`Migrated users: ${result.modifiedCount}`);
    await mongoose.connection.close();
    process.exit(0);
  } catch (e) {
    console.error('Migration failed:', e);
    process.exit(1);
  }
})();


